<?php

namespace common\models;

use api\models\Good;
use Yii;

/**
 * This is the model class for table "job_info".
 *
 * @property int $id
 * @property int $jid 工作id
 * @property int $job_type 兼职类型(fk)
 * @property int $mission_type 任务类型(fk)
 * @property int $img 图片
 * @property string $color 文字颜色
 * @property string $latitude 纬度
 * @property string $longitude 经度
 * @property string $province_code 省行政区划
 * @property string $city_code 市行政区划
 * @property string $district_code 区/县行政区划
 * @property string $ad_code 行政区划码
 * @property string $ad_type 行政区级别
 * @property int $gender_needed 性别要求
 * @property int $age_needed 年龄要求
 * @property int $sign_start 报名开始时间
 * @property int $sign_end 报名结束时间
 * @property string $work_start 上班时间
 * @property string $work_end 下班时间
 * @property int $salary 工资
 * @property int $salary_type 工资类型 元/天
 * @property int $pay_typed 结算方式 日结/月结
 * @property int $good_id 结算方式
 * @property int $start_at 兼职开始时间
 * @property int $end_at 兼职结束时间
 * @property int $people_num 招聘人数
 *
 * @property Job $j
 * @property Image $img0
 * @property Goods $good
 */
class JobInfo extends \yii\db\ActiveRecord
{

    const GENDER_NEED_MAN = 1;
    const GENDER_NEED_WOMEN = 2;
    const GENDER_NEED_ALL = 3;

    const SALARY_TYPE_DAY = 1;
    const SALARY_TYPE_WEEK = 2;
    const SALARY_TYPE_MONTH = 3;

    const PAY_TYPE_DAY = 1;
    const PAY_TYPE_WEEK = 2;
    const PAY_TYPE_MONTH = 3;


    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'job_info';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['jid'], 'required'],
            [
                [
                    'jid',
                    'job_type',
                    'mission_type',
                    'img',
                    'gender_needed',
                    'age_needed',
                    'sign_start',
                    'sign_end',
                    'salary',
                    'salary_type',
                    'pay_typed',
                    'people_num'
                ],
                'integer'
            ],
            [['work_start', 'work_end'], 'safe'],
            [
                ['color', 'latitude', 'longitude', 'province_code', 'city_code', 'district_code', 'ad_code', 'ad_type'],
                'string',
                'max' => 255
            ],
            [
                ['jid'],
                'exist',
                'skipOnError'     => true,
                'targetClass'     => Job::className(),
                'targetAttribute' => ['jid' => 'id']
            ],
            [
                ['img'],
                'exist',
                'skipOnError'     => true,
                'targetClass'     => Image::className(),
                'targetAttribute' => ['img' => 'id']
            ],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id'            => 'ID',
            'jid'           => '工作id',
            'job_type'      => '兼职类型(fk)',
            'mission_type'  => '任务类型(fk)',
            'img'           => '图片',
            'color'         => '文字颜色',
            'latitude'      => '纬度',
            'longitude'     => '经度',
            'province_code' => '省行政区划',
            'city_code'     => '市行政区划',
            'district_code' => '区/县行政区划',
            'ad_code'       => '行政区划码',
            'ad_type'       => '行政区级别',
            'gender_needed' => '性别要求',
            'age_needed'    => '年龄要求',
            'sign_start'    => '报名开始时间',
            'sign_end'      => '报名结束时间',
            'work_start'    => '上班时间',
            'work_end'      => '下班时间',
            'salary'        => '工资',
            'salary_type'   => '工资类型',
            'pay_typed'     => '结算方式',
            'start_at'      => '兼职开始时间',
            'end_at'        => '兼职结束时间',
            'people_num'    => '兼职人数'
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getJ()
    {
        return $this->hasOne(Job::className(), ['id' => 'jid']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getImg0()
    {
        return $this->hasOne(Image::className(), ['id' => 'img']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGood()
    {
        return $this->hasOne(Goods::className(), ['id' => 'good_id']);
    }
}
